﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

namespace DAL
{
     [Serializable]
     public class MeasurementInfoData
     {

         public const string IDField ="@ID";

         public const string PRIMARYKEY_Field=@"ID";

         public const string SUPERIORIDField ="@SuperiorID";

         public const string NAMEField ="@Name";

         public const string CALLNUMField ="@CallNum";

         public const string DEVICETYPEField ="@DeviceType";

         public const string ADJUSTField ="@Adjust";

         public const string ADDRESSField ="@Address";

         public const string TELEPHONEField ="@Telephone";

         public const string REMARKField ="@Remark";

         public const string CREATORField ="@Creator";

         public const string CREATETIMEField ="@CreateTime";

         public const string UPDATETIMEField ="@UpdateTime";

         public const string NUMBER1Field ="@Number1";

         public const string NUMBER2Field ="@Number2";

         private Guid _ID;

         private Guid _SuperiorID;

         private String _Name;

         private String _CallNum;

         private String _DeviceType;

         private Int32 _Adjust;

         private String _Address;

         private String _Telephone;

         private String _Remark;

         private String _Creator;

         private DateTime _CreateTime;

         private DateTime _UpdateTime;

         private String _Number1;

         private String _Number2;

         public Guid ID
         {
             get{ return _ID;}
             set{ _ID=value;}
         }
         public Guid SuperiorID
         {
             get{ return _SuperiorID;}
             set{ _SuperiorID=value;}
         }
         public String Name
         {
             get{ return _Name;}
             set{ _Name=value;}
         }
         public String CallNum
         {
             get{ return _CallNum;}
             set{ _CallNum=value;}
         }
         public String DeviceType
         {
             get{ return _DeviceType;}
             set{ _DeviceType=value;}
         }
         public Int32 Adjust
         {
             get{ return _Adjust;}
             set{ _Adjust=value;}
         }
         public String Address
         {
             get{ return _Address;}
             set{ _Address=value;}
         }
         public String Telephone
         {
             get{ return _Telephone;}
             set{ _Telephone=value;}
         }
         public String Remark
         {
             get{ return _Remark;}
             set{ _Remark=value;}
         }
         public String Creator
         {
             get{ return _Creator;}
             set{ _Creator=value;}
         }
         public DateTime CreateTime
         {
             get{ return _CreateTime;}
             set{ _CreateTime=value;}
         }
         public DateTime UpdateTime
         {
             get{ return _UpdateTime;}
             set{ _UpdateTime=value;}
         }
         public String Number1
         {
             get{ return _Number1;}
             set{ _Number1=value;}
         }
         public String Number2
         {
             get{ return _Number2;}
             set{ _Number2=value;}
         }
         public MeasurementInfoData()
         {
             _ID=Guid.Empty;
             _SuperiorID=Guid.Empty;
             _Name="";
             _CallNum="";
             _DeviceType="";
             _Adjust=0;
             _Address="";
             _Telephone="";
             _Remark="";
             _Creator="";
             _CreateTime=DateTime.Now;
             _UpdateTime=DateTime.Now;
             _Number1="";
             _Number2="";
         }
     }

     public class MeasurementInfoDataFactory
     {
         public static MeasurementInfoData Construct(IDataReader reader)
         {
             MeasurementInfoData data = new MeasurementInfoData();

             try{  data.ID = (Guid)(reader["ID"]) ;} catch { } 

             try{  data.SuperiorID = (Guid)(reader["SuperiorID"]) ;} catch { } 

             try{  data.Name = Convert.ToString(reader["Name"])  ;} catch { } 

             try{  data.CallNum = Convert.ToString(reader["CallNum"])  ;} catch { } 

             try{  data.DeviceType = Convert.ToString(reader["DeviceType"])  ;} catch { } 

             try{  data.Adjust = Convert.ToInt32(reader["Adjust"])  ;} catch { } 

             try{  data.Address = Convert.ToString(reader["Address"])  ;} catch { } 

             try{  data.Telephone = Convert.ToString(reader["Telephone"])  ;} catch { } 

             try{  data.Remark = Convert.ToString(reader["Remark"])  ;} catch { } 

             try{  data.Creator = Convert.ToString(reader["Creator"])  ;} catch { } 

             try{  data.CreateTime = Convert.ToDateTime(reader["CreateTime"])  ;} catch { } 

             try{  data.UpdateTime = Convert.ToDateTime(reader["UpdateTime"])  ;} catch { } 

             try{  data.Number1 = Convert.ToString(reader["Number1"])  ;} catch { } 

             try{  data.Number2 = Convert.ToString(reader["Number2"])  ;} catch { } 

             return data;
         }
         public static Guid GetPrimaryKey(DataTable dt)
         {
             return GetPrimaryKey(dt,0);
         }
         public static Guid GetPrimaryKey(DataTable dt,int rowIndex)
         {
             Guid PrimaryKey=Guid.Empty;

             if(dt.Rows.Count<rowIndex+1)

                 return Guid.Empty;

             DataRow dr=dt.Rows[rowIndex];

             if(dr==null)

                 return Guid.Empty;

             try{ PrimaryKey = (Guid)(dr[MeasurementInfoData.PRIMARYKEY_Field]) ;} catch { } 

             return PrimaryKey;
         }
         public static MeasurementInfoData Construct(DataTable dt)
         {
             return Construct(dt,0);
         }
         public static MeasurementInfoData Construct(DataTable dt,int rowIndex)
         {
             MeasurementInfoData data = new MeasurementInfoData();

             if(dt.Rows.Count<rowIndex+1)

                 return null;

             DataRow dr=dt.Rows[rowIndex];

             if(dr==null)

                 return null;

             try{ data.ID = new Guid(dr["ID"].ToString()) ;} catch { } 

             try{ data.SuperiorID = new Guid(dr["SuperiorID"].ToString()) ;} catch { } 

             try{ data.Name = Convert.ToString(dr["Name"]) ;} catch { } 

             try{ data.CallNum = Convert.ToString(dr["CallNum"]) ;} catch { } 

             try{ data.DeviceType = Convert.ToString(dr["DeviceType"]) ;} catch { } 

             try{ data.Adjust = Convert.ToInt32(dr["Adjust"]) ;} catch { } 

             try{ data.Address = Convert.ToString(dr["Address"]) ;} catch { } 

             try{ data.Telephone = Convert.ToString(dr["Telephone"]) ;} catch { } 

             try{ data.Remark = Convert.ToString(dr["Remark"]) ;} catch { } 

             try{ data.Creator = Convert.ToString(dr["Creator"]) ;} catch { } 

             try{ data.CreateTime = Convert.ToDateTime(dr["CreateTime"]) ;} catch { } 

             try{ data.UpdateTime = Convert.ToDateTime(dr["UpdateTime"]) ;} catch { } 

             try{ data.Number1 = Convert.ToString(dr["Number1"]) ;} catch { } 

             try{ data.Number2 = Convert.ToString(dr["Number2"]) ;} catch { } 

             return data;
         }
         public static MeasurementInfoData Construct(DataRow dr)
         {
             MeasurementInfoData data = new MeasurementInfoData();

             try{ data.ID = new Guid(dr["ID"].ToString()) ;} catch { } 

             try{ data.SuperiorID = new Guid(dr["SuperiorID"].ToString()) ;} catch { } 

             try{ data.Name = Convert.ToString(dr["Name"]) ;} catch { } 

             try{ data.CallNum = Convert.ToString(dr["CallNum"]) ;} catch { } 

             try{ data.DeviceType = Convert.ToString(dr["DeviceType"]) ;} catch { } 

             try{ data.Adjust = Convert.ToInt32(dr["Adjust"]) ;} catch { } 

             try{ data.Address = Convert.ToString(dr["Address"]) ;} catch { } 

             try{ data.Telephone = Convert.ToString(dr["Telephone"]) ;} catch { } 

             try{ data.Remark = Convert.ToString(dr["Remark"]) ;} catch { } 

             try{ data.Creator = Convert.ToString(dr["Creator"]) ;} catch { } 

             try{ data.CreateTime = Convert.ToDateTime(dr["CreateTime"]) ;} catch { } 

             try{ data.UpdateTime = Convert.ToDateTime(dr["UpdateTime"]) ;} catch { } 

             try{ data.Number1 = Convert.ToString(dr["Number1"]) ;} catch { } 

             try{ data.Number2 = Convert.ToString(dr["Number2"]) ;} catch { } 

             return data;
         }
         public static Guid GetPrimaryKey(DataRow dr)
         {
             Guid PrimaryKey=Guid.Empty;

             try{ PrimaryKey = (Guid)(dr[MeasurementInfoData.PRIMARYKEY_Field]) ;} catch { } 
                 return PrimaryKey;
         }

     }
     public class MeasurementInfoDataDBOption
     {
         public static int Insert(MeasurementInfoData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("insert into MeasurementInfo (");
             sql.Append("SuperiorID, ");
             sql.Append("Name, ");
             sql.Append("CallNum, ");
             sql.Append("DeviceType, ");
             sql.Append("Adjust, ");
             sql.Append("Address, ");
             sql.Append("Telephone, ");
             sql.Append("Remark, ");
             sql.Append("Creator, ");
             sql.Append("CreateTime, ");
             sql.Append("UpdateTime, ");
             sql.Append("Number1, ");
             sql.Append("Number2");
             sql.Append(") values (");
             sql.Append("'");
             sql.Append(d.SuperiorID.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Name.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.CallNum.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.DeviceType.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("");
             sql.Append(d.Adjust.ToString());
             sql.Append("");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Address.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Telephone.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Remark.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Creator.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"));
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Number1.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("'");
             sql.Append(d.Number2.ToString());
             sql.Append("'");
             sql.Append(")");
             return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
         }
         public static int Update(MeasurementInfoData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("update MeasurementInfo set ");
             sql.Append("SuperiorID=");
             sql.Append("'");
             sql.Append(d.SuperiorID.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Name=");
             sql.Append("'");
             sql.Append(d.Name.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("CallNum=");
             sql.Append("'");
             sql.Append(d.CallNum.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("DeviceType=");
             sql.Append("'");
             sql.Append(d.DeviceType.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Adjust=");
             sql.Append("");
             sql.Append(d.Adjust.ToString());
             sql.Append("");
             sql.Append(", ");
             sql.Append("Address=");
             sql.Append("'");
             sql.Append(d.Address.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Telephone=");
             sql.Append("'");
             sql.Append(d.Telephone.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Remark=");
             sql.Append("'");
             sql.Append(d.Remark.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Creator=");
             sql.Append("'");
             sql.Append(d.Creator.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("CreateTime=");
             sql.Append("'");
             sql.Append(d.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"));
             sql.Append("'");
             sql.Append(", ");
             sql.Append("UpdateTime=");
             sql.Append("'");
             sql.Append(d.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"));
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Number1=");
             sql.Append("'");
             sql.Append(d.Number1.ToString());
             sql.Append("'");
             sql.Append(", ");
             sql.Append("Number2=");
             sql.Append("'");
             sql.Append(d.Number2.ToString());
             sql.Append("'");
             sql.Append(" where ID='");
             sql.Append(d.ID.ToString());
             sql.Append("'");
             return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
         }
         public static int Delete(MeasurementInfoData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("delete from MeasurementInfo ");
             sql.Append(" where ID='");
             sql.Append(d.ID.ToString());
             sql.Append("'");
             return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
         }
         public static DataTable DataTableSelect()
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from MeasurementInfo ");
             return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
         }
         public static DataTable DataTableSelect(MeasurementInfoData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from MeasurementInfo where ID=");
             sql.Append(d.ID.ToString());
             return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
         }
         public static DataSet DataSetSelect()
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from MeasurementInfo ");
             return WFNetLib.ADO.SQLServerOP.DataSetSQL(sql.ToString());
         }
         public static SqlDataReader ReaderSelect(MeasurementInfoData d)
         {
             StringBuilder sql=new StringBuilder();
             sql.Append("select * from MeasurementInfo ");
             return WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(sql.ToString());
         }


         public static MeasurementInfoData SelectByID(Guid id)
         {
             StringBuilder sql = new StringBuilder();
             sql.Append("select * from MeasurementInfo where ID='");
             sql.Append(id.ToString());
             sql.Append("'");
             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
             if (dt.Rows.Count != 0)
                 return MeasurementInfoDataFactory.Construct(dt.Rows[0]);
             else
                 return null;
         }

         public static MeasurementInfoData SelectByCallNum(string callnum)
         {
             StringBuilder sql = new StringBuilder();
             sql.Append("select * from MeasurementInfo where CallNum='");
             sql.Append(callnum);
             sql.Append("'");
             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
             if (dt.Rows.Count != 0)
                 return MeasurementInfoDataFactory.Construct(dt.Rows[0]);
             else
                 return null;
         }

         public static DataTable SelectByFrameID(Guid frameid)
         {
             StringBuilder sql = new StringBuilder();
             sql.Append("select * from MeasurementInfo where SuperiorID='");
             sql.Append(frameid.ToString());
             sql.Append("'");
             return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
         }

         public static int DeleteByID(Guid id)
         {
             StringBuilder sql = new StringBuilder();
             sql.Append("delete from MeasurementInfo ");
             sql.Append(" where ID='");
             sql.Append(id.ToString());
             sql.Append("'");
             return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
         }
     }
}


